package org.marketlive.system.encryption;

import java.io.IOException;
import java.util.List;

/*
(C) Copyright MarketLive. 2006. All rights reserved.
MarketLive is a trademark of MarketLive, Inc.
Warning: This computer program is protected by copyright law and international treaties.
Unauthorized reproduction or distribution of this program, or any portion of it, may result
in severe civil and criminal penalties, and will be prosecuted to the maximum extent
possible under the law.
*/


import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;

/**
 * Interface for KeyStoreManager methods.
 */
public interface IKeyStoreManager {
    /**
     * Create a KeyStore object with the given code, privateKey, publicKey, and isSymmetric status.
     *
     * If isSymmetric = true, then privateKey = password encryption/decryption key, publicKey = null
     * If isSymmetric = false, then privateKey = ccNum decryption key, publicKey = ccNum encryption key.
     *
     * @param code  The unique identifier for this object.
     * @param privateKey a byte array with private key data.
     * @param publicKey  a byte array with the public key data.
     * @param isPasswordKey set to true if the private key sent is a password encryption/decryption key.
     * @param isPasswordKey set to true if this is to be the active encryption scheme used..
     */
    void createKeyStore(String code, String privateKey, String publicKey, boolean isPasswordKey, boolean isActive);

    /**
     * Find the KeyStore object with the given code.
     *
     * @param code a string identifier.
     * @return returns a keyStore object.
     */
    IKeyStore findByCode(String code);

    /**
     * Find the KeyStore object which is active (STATUS = 1).
     *
     * @return returns a keyStore object.
     */
    IKeyStore findActiveKeystore();

    /**
     * Find all KeyStore objects.
     *
     * @return returns a list keyStore objects.
     */
    List findAll();

    /**
     * Delete the given keyStore object.
     * @param keyStore the KeyStore object to delete.
     */
    void removeKeyStore(IKeyStore keyStore);

    /**
     * Update the given KeyStore object.
     * @param keyStore the KeyStore object to update.
     */
    void updateKeyStore(IKeyStore keyStore);

    /**
     * Make the given keystore active and deactive all others..
     * @param keyStore the KeyStore object to activate.
     */
    void updateActiveStatus(IKeyStore keyStore);
    
    /**
     * Once the keystore is initialized set the current keystore.
     * @param currentKeyStore The keystore initialized or newly created.
     */
    void setCurrentKeyStore(IKeyStore currentKeyStore);
    
    /**
     * Get the current keystore.
     * @return The current active keystore.
     */
    IKeyStore getCurrentKeyStore();    
    
    /**
     * Returns the public key for the active key store.
     * @return Public key as a String.
     */
    String getPublicKey();
    
    /**
     * Get the private key for the active key store.
     * @return  Private key as a String.
     */
    String getPrivateKey(); 
    
    /**
     * Get the key code for the active key store.
     * @return Key code as a string.
     */
    String getKeyCode();  
    
    /**
     * Encode a byte array in Base64 and return an encoded string.
     * @param bytes A byte array to be encoded
     * @return A string that is Base64 encoded representing the input byte array.
     * @throws EncoderException
     */
    String encodeBase64(byte[] bytes) throws EncoderException;
    
    /**
     * Decode a string encoded in Base64 and return a byte array.
     * @param text A Base64 encoded string to be decoded.
     * @return A byte array representing the decode input string.
     * @throws DecoderException
     */
    byte[] decodeBase64(String text) throws DecoderException;
    
    /**
     * This method makes a null String object or "null" string a blank string.
     * @param inString java.lang.String
     * @return java.lang.String
     */
    String makeBlank(String inString); 
     
    /**
     * Set provider info via Spring injection.
     */
	void setProviderInfo(String providerInfo);
	
    /**
     * Get provider info as injected by Spring.
     */
	String getProviderInfo();	
	
    /**
     * Set key code via Spring injection.
     * @param keyCode
     */
    void setKeyCode(String keyCode);    
	
}
